<%@ page language="java"  pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>知识分类管理</title>
<link href="<%=path %>/styles/main.css" rel="stylesheet" type="text/css" />
<link href="<%=path %>/js/jtree/css/tree.css" rel="stylesheet" type="text/css" />
<link href="<%=path %>/js/dialog/skin/ymPrompt.css"  rel="stylesheet" id='skin' type="text/css"/>
<script src="<%=path %>/js/main.js" type="text/javascript" ></script>
<script src="<%=path %>/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="<%=path %>/js/jtree/tree.js" type="text/javascript" ></script> 
<script type="text/javascript" src="<%=path %>/js/dialog/ymPrompt.js" ></script>
<script type="text/javascript">
	var topMenuIndex=3;
	var menuIndex=2;
</script>
</head>
<body>
<%@ include file="../common/Header.jsp"%>
<%@ include file="Menu.jsp"%>	
<div id="DetailContent">
	<!----------DocTree-->
  	<div style="height:400px;">
  	  	<div id="tree"></div>
	  		<script type="text/javascript">
		  	  var treedata=[{ "id": "0", "text": "知识分类", "value": "0", "showcheck": true, "isexpand": false, "checkstate": 0, "hasChildren": true, "ChildNodes": null, "complete": false }];
		      var userAgent = window.navigator.userAgent.toLowerCase();
		      $.browser.msie8 = $.browser.msie && /msie 8\.0/i.test(userAgent);
		      $.browser.msie7 = $.browser.msie && /msie 7\.0/i.test(userAgent);
		      $.browser.msie6 = !$.browser.msie8 && !$.browser.msie7 && $.browser.msie && /msie 6\.0/i.test(userAgent);
		      function load() {        
		          var o = {
		          	showcheck: false,
		          	onnodeclick:function(item){view(item.id);},          
		          	url: "<%=path %>/km/type/list.do",
		          	imagepath:"<%=path %>/js/jtree/images/"          	
		          };
		          o.data = treedata; 
		          $("#tree").treeview(o); 
		      }  
		       //加载树
		      if( $.browser.msie6){load();}else{$(document).ready(load);}      
		    </script>
	</div> 
	<!----------ToolBar--->
  	<div  id="FormToobar" class="clear">	
		<div id="LeftMns" >
			<tt><input name="btnNew" type="button" class="But" value="新建" onclick="newType();"/> </tt>
		    <tt><input name="btnUpdate" type="button" class="But" value="重命名" onclick="updateType();" /></tt>
		    <tt><input name="btnDelete" type="button" class="But" value="删除" onclick="deleteType();" /></tt>
		    <tt><input name="btnMove" type="button" class="But" value="移动" onclick="moveType();" /></tt>
		</div>	
  	</div>
</div>
<script type="text/javascript">
	function newType(){	
		var s=$("#tree").getTCT();
		if(s==undefined){
			ymPrompt.alert({title:'提示信息',message:'请选择上级分类！'});
			return;
		}
		ymPrompt.win({title:'新建分类',width:400,height:200,iframe:{id:'myId',name:'myName',src:'<%=path%>/km/type/load.do?operation=add&typeId='+s.id}})
	}
	function deleteType(){
		var s=$("#tree").getTCT();
		if(s==undefined){
			ymPrompt.alert({title:'提示信息',message:'请选择要删除的分类！'});
			return;
		}	
	  	$.post("<%=path %>/km/type/del.do",
	     		  {typeId:s.id},
	     		  function(data){      		 
	     		  	if(data=="delete"){
		               	refreshTree('delete');
		               	ymPrompt.succeedInfo({title:'提示信息',message:'删除成功！'});	               	
	              	}else if(data=="exist"){
	              		ymPrompt.alert({title:'提示信息',message:'请先删除该分类下其它分类！'});	 
	              	}else{
	              		ymPrompt.errorInfo({title:'提示信息',message:'操作失败！'});	             
	              	}
	     		  },"string");
	}
	function moveType(){
		var s=$("#tree").getTCT();
		ymPrompt.win({title:'分类移动',width:300,height:400,iframe:{id:'myId',name:'myName',src:'<%=path%>/km/type/toMove.do?typeId='+s.id}});
	}
	function updateType(){
		var s=$("#tree").getTCT();
		if(s==undefined){
			ymPrompt.alert({title:'提示信息',message:'请选择要重命名的分类！'});
			return;
		}	
		ymPrompt.win({title:'分类重命名',width:400,height:200,iframe:{id:'myId',name:'myName',src:'<%=path%>/km/type/load.do?operation=update&typeId='+s.id}});
	}
	function refreshTree(op,retTypeId){
		var s=$("#tree").getTCT();
		if(op=='add'){
			$("#tree").refresh(s.id);
		}else if(op=='update'){
			$("#tree").refresh(s.pid);
		}else if(op=='move'){
			$("#tree").refresh(s.pid);
			$("#tree").refresh(retTypeId);
		}else if(op=='delete'){
			$("#tree").refresh(s.pid);
		}		
	}
</script>
</body>
</html>
